<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>png++: info.hpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">png++
   &#160;<span id="projectnumber">0.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">info.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="info_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2007,2008   Alex Shulgin</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This file is part of png++ the C++ wrapper for libpng.  PNG++ is free</span>
<a name="l00005"></a>00005 <span class="comment"> * software; the exact copying conditions are as follows:</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00008"></a>00008 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright notice,</span>
<a name="l00011"></a>00011 <span class="comment"> * this list of conditions and the following disclaimer.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
<a name="l00015"></a>00015 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * 3. The name of the author may not be used to endorse or promote products</span>
<a name="l00018"></a>00018 <span class="comment"> * derived from this software without specific prior written permission.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS&#39;&#39; AND ANY EXPRESS OR</span>
<a name="l00021"></a>00021 <span class="comment"> * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</span>
<a name="l00022"></a>00022 <span class="comment"> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN</span>
<a name="l00023"></a>00023 <span class="comment"> * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00024"></a>00024 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED</span>
<a name="l00025"></a>00025 <span class="comment"> * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR</span>
<a name="l00026"></a>00026 <span class="comment"> * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span>
<a name="l00027"></a>00027 <span class="comment"> * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
<a name="l00028"></a>00028 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00029"></a>00029 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00030"></a>00030 <span class="comment"> */</span>
<a name="l00031"></a>00031 <span class="preprocessor">#ifndef PNGPP_INFO_HPP_INCLUDED</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define PNGPP_INFO_HPP_INCLUDED</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="info__base_8hpp.html">info_base.hpp</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="image__info_8hpp.html">image_info.hpp</a>&quot;</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="keyword">namespace </span>png
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 
<a name="l00045"></a><a class="code" href="classpng_1_1info.html">00045</a>     <span class="keyword">class </span><a class="code" href="classpng_1_1info.html" title="Holds information about PNG image. Adapter class for IO image operations.">info</a>
<a name="l00046"></a>00046         : <span class="keyword">public</span> <a class="code" href="classpng_1_1info__base.html" title="Internal class to hold PNG info or end_info.">info_base</a>,
<a name="l00047"></a>00047           <span class="keyword">public</span> <a class="code" href="classpng_1_1image__info.html" title="Holds information about PNG image.">image_info</a>
<a name="l00048"></a>00048     {
<a name="l00049"></a>00049     <span class="keyword">public</span>:
<a name="l00050"></a><a class="code" href="classpng_1_1info.html#a6de7c51766261018632d21405e3a2563">00050</a>         <a class="code" href="classpng_1_1info.html#a6de7c51766261018632d21405e3a2563">info</a>(<a class="code" href="classpng_1_1io__base.html" title="Base class for PNG reader/writer classes.">io_base</a>&amp; io, png_struct* png)
<a name="l00051"></a>00051             : <a class="code" href="classpng_1_1info__base.html" title="Internal class to hold PNG info or end_info.">info_base</a>(io, png)
<a name="l00052"></a>00052         {
<a name="l00053"></a>00053         }
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="classpng_1_1info.html#a8788080158fc7450911516c23d4b584c">00055</a>         <span class="keywordtype">void</span> <a class="code" href="classpng_1_1info.html#a8788080158fc7450911516c23d4b584c">read</a>()
<a name="l00056"></a>00056         {
<a name="l00057"></a>00057             assert(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>);
<a name="l00058"></a>00058             assert(<a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00059"></a>00059 
<a name="l00060"></a>00060             png_read_info(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00061"></a>00061             png_get_IHDR(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>,
<a name="l00062"></a>00062                          <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>,
<a name="l00063"></a>00063                          &amp; <a class="code" href="classpng_1_1image__info.html#a4acee97cd5ab36c631099e788ffdf08c">m_width</a>,
<a name="l00064"></a>00064                          &amp; <a class="code" href="classpng_1_1image__info.html#ad36dc08da3efe4e26322e3c8eb55adfc">m_height</a>,
<a name="l00065"></a>00065                          reinterpret_cast&lt; int* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#a09d04b19ad511e5f4249e9dfa0e62efa">m_bit_depth</a>),
<a name="l00066"></a>00066                          reinterpret_cast&lt; int* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#a196348cce026bf93062a80eff78958e7">m_color_type</a>),
<a name="l00067"></a>00067                          reinterpret_cast&lt; int* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#a988c3d5bfead5238afa04a1061e0f04a">m_interlace_type</a>),
<a name="l00068"></a>00068                          reinterpret_cast&lt; int* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#aace206556a5c185a86542702b72a45dc">m_compression_type</a>),
<a name="l00069"></a>00069                          reinterpret_cast&lt; int* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#aaa7afab91bfab66e0daa966695d40967">m_filter_type</a>));
<a name="l00070"></a>00070 
<a name="l00071"></a>00071             <span class="keywordflow">if</span> (png_get_valid(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>, <a class="code" href="namespacepng.html#a93bd423c4b470bcea62b3664e835ec87ab9358a8acd5c721d678807e639761a09">chunk_PLTE</a>) == <a class="code" href="namespacepng.html#a93bd423c4b470bcea62b3664e835ec87ab9358a8acd5c721d678807e639761a09">chunk_PLTE</a>)
<a name="l00072"></a>00072             {
<a name="l00073"></a>00073                 png_color* colors = 0;
<a name="l00074"></a>00074                 <span class="keywordtype">int</span> count = 0;
<a name="l00075"></a>00075                 png_get_PLTE(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>, &amp; colors, &amp; count);
<a name="l00076"></a>00076                 <a class="code" href="classpng_1_1image__info.html#a1fb1b97e0f153d8203aa79d667b488c8">m_palette</a>.assign(colors, colors + count);
<a name="l00077"></a>00077             }
<a name="l00078"></a>00078 <span class="preprocessor">#ifdef PNG_tRNS_SUPPORTED</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (png_get_valid(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>, <a class="code" href="namespacepng.html#a93bd423c4b470bcea62b3664e835ec87aef2ac03a3d930bb1701988dae298a1af">chunk_tRNS</a>) == <a class="code" href="namespacepng.html#a93bd423c4b470bcea62b3664e835ec87aef2ac03a3d930bb1701988dae298a1af">chunk_tRNS</a>)
<a name="l00080"></a>00080             {
<a name="l00081"></a>00081                 <span class="keywordflow">if</span> (<a class="code" href="classpng_1_1image__info.html#a196348cce026bf93062a80eff78958e7">m_color_type</a> == <a class="code" href="namespacepng.html#a4f30149e7da9c8d70e84e6977a7f74daa11ca0096a8c002514f3ba1599a42d407">color_type_palette</a>)
<a name="l00082"></a>00082                 {
<a name="l00083"></a>00083                     <span class="keywordtype">int</span> count;
<a name="l00084"></a>00084                     <a class="code" href="namespacepng.html#ac0e0e2e09bdd9a287618bfdc5f31ca52">byte</a>* values;
<a name="l00085"></a>00085                     <span class="keywordflow">if</span> (png_get_tRNS(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>, &amp; values, &amp; count, NULL)
<a name="l00086"></a>00086                         != PNG_INFO_tRNS)
<a name="l00087"></a>00087                     {
<a name="l00088"></a>00088                         <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;png_get_tRNS() failed&quot;</span>);
<a name="l00089"></a>00089                     }
<a name="l00090"></a>00090                     <a class="code" href="classpng_1_1image__info.html#ae16512ad01beea645e75e0edd60f0720">m_tRNS</a>.assign(values, values + count);
<a name="l00091"></a>00091                 }
<a name="l00092"></a>00092             }
<a name="l00093"></a>00093 <span class="preprocessor">#endif</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span>        }
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="classpng_1_1info.html#a863333fbef670b244920022d1a0ee210">00096</a>         <span class="keywordtype">void</span> <a class="code" href="classpng_1_1info.html#a863333fbef670b244920022d1a0ee210">write</a>()<span class="keyword"> const</span>
<a name="l00097"></a>00097 <span class="keyword">        </span>{
<a name="l00098"></a>00098             assert(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>);
<a name="l00099"></a>00099             assert(<a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00100"></a>00100 
<a name="l00101"></a>00101             <a class="code" href="classpng_1_1info.html#a76309c30eb25d8242ae039a2e80bb1d3">sync_ihdr</a>();
<a name="l00102"></a>00102             <span class="keywordflow">if</span> (<a class="code" href="classpng_1_1image__info.html#a196348cce026bf93062a80eff78958e7">m_color_type</a> == <a class="code" href="namespacepng.html#a4f30149e7da9c8d70e84e6977a7f74daa11ca0096a8c002514f3ba1599a42d407">color_type_palette</a>)
<a name="l00103"></a>00103             {
<a name="l00104"></a>00104                 <span class="keywordflow">if</span> (! <a class="code" href="classpng_1_1image__info.html#a1fb1b97e0f153d8203aa79d667b488c8">m_palette</a>.empty())
<a name="l00105"></a>00105                 {
<a name="l00106"></a>00106                     png_set_PLTE(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>,
<a name="l00107"></a>00107                                  const_cast&lt; color* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#a1fb1b97e0f153d8203aa79d667b488c8">m_palette</a>[0]),
<a name="l00108"></a>00108                                  <a class="code" href="classpng_1_1image__info.html#a1fb1b97e0f153d8203aa79d667b488c8">m_palette</a>.size());
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110                 <span class="keywordflow">if</span> (! <a class="code" href="classpng_1_1image__info.html#ae16512ad01beea645e75e0edd60f0720">m_tRNS</a>.empty())
<a name="l00111"></a>00111                 {
<a name="l00112"></a>00112 <span class="preprocessor">#ifdef PNG_tRNS_SUPPORTED</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span>                    png_set_tRNS(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>,
<a name="l00114"></a>00114                                  const_cast&lt; byte* &gt;(&amp; <a class="code" href="classpng_1_1image__info.html#ae16512ad01beea645e75e0edd60f0720">m_tRNS</a>[0]),
<a name="l00115"></a>00115                                  <a class="code" href="classpng_1_1image__info.html#ae16512ad01beea645e75e0edd60f0720">m_tRNS</a>.size(),
<a name="l00116"></a>00116                                  NULL);
<a name="l00117"></a>00117 <span class="preprocessor">#else</span>
<a name="l00118"></a>00118 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;attempted to write tRNS chunk;&quot;</span>
<a name="l00119"></a>00119                                 <span class="stringliteral">&quot; recompile with PNG_tRNS_SUPPORTED&quot;</span>);
<a name="l00120"></a>00120 <span class="preprocessor">#endif</span>
<a name="l00121"></a>00121 <span class="preprocessor"></span>                }
<a name="l00122"></a>00122             }
<a name="l00123"></a>00123             png_write_info(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00124"></a>00124         }
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="classpng_1_1info.html#a544c5e25c4211ef33976e3ac2b2ea020">00126</a>         <span class="keywordtype">void</span> <a class="code" href="classpng_1_1info.html#a544c5e25c4211ef33976e3ac2b2ea020">update</a>()
<a name="l00127"></a>00127         {
<a name="l00128"></a>00128             assert(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>);
<a name="l00129"></a>00129             assert(<a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131             <a class="code" href="classpng_1_1info.html#a76309c30eb25d8242ae039a2e80bb1d3">sync_ihdr</a>();
<a name="l00132"></a>00132             png_read_update_info(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>, <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>);
<a name="l00133"></a>00133         }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135     <span class="keyword">protected</span>:
<a name="l00136"></a><a class="code" href="classpng_1_1info.html#a76309c30eb25d8242ae039a2e80bb1d3">00136</a>         <span class="keywordtype">void</span> <a class="code" href="classpng_1_1info.html#a76309c30eb25d8242ae039a2e80bb1d3">sync_ihdr</a>(<span class="keywordtype">void</span>)<span class="keyword"> const</span>
<a name="l00137"></a>00137 <span class="keyword">        </span>{
<a name="l00138"></a>00138             png_set_IHDR(<a class="code" href="classpng_1_1info__base.html#ab2052faecb79f17e2b0bb697e0cbbb46">m_png</a>,
<a name="l00139"></a>00139                          <a class="code" href="classpng_1_1info__base.html#a55a07d9e2ff9660850e5a1c9156e076a">m_info</a>,
<a name="l00140"></a>00140                          <a class="code" href="classpng_1_1image__info.html#a4acee97cd5ab36c631099e788ffdf08c">m_width</a>,
<a name="l00141"></a>00141                          <a class="code" href="classpng_1_1image__info.html#ad36dc08da3efe4e26322e3c8eb55adfc">m_height</a>,
<a name="l00142"></a>00142                          <a class="code" href="classpng_1_1image__info.html#a09d04b19ad511e5f4249e9dfa0e62efa">m_bit_depth</a>,
<a name="l00143"></a>00143                          <a class="code" href="classpng_1_1image__info.html#a196348cce026bf93062a80eff78958e7">m_color_type</a>,
<a name="l00144"></a>00144                          <a class="code" href="classpng_1_1image__info.html#a988c3d5bfead5238afa04a1061e0f04a">m_interlace_type</a>,
<a name="l00145"></a>00145                          <a class="code" href="classpng_1_1image__info.html#aace206556a5c185a86542702b72a45dc">m_compression_type</a>,
<a name="l00146"></a>00146                          <a class="code" href="classpng_1_1image__info.html#aaa7afab91bfab66e0daa966695d40967">m_filter_type</a>);
<a name="l00147"></a>00147         }
<a name="l00148"></a>00148     };
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 } <span class="comment">// namespace png</span>
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 <span class="preprocessor">#endif // PNGPP_INFO_HPP_INCLUDED</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Jan 25 2013 14:10:10 for png++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
